import * as actions from '../actions/index';

// 对页面prop 数据进行管理
const initialState = {
  tabKey: 'pipeline',
  search: '',
  pipelines: [],
  total: 0,
  currentPage: 1,
  pageSize: 10,
  isLoading: true,
  advancedSearchData: {},
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.RECEIVE_DATA: {
      return {
        ...state,
        pipelines: action.data.list,
        currentPage: action.data.currentPage,
        total: action.data.total,
        isLoading: false,
        isDidMount: action.data.isDidMount,
      };
    }
    case actions.SET_LOADING:
      return { ...state, isLoading: true };
    case actions.SET_SEARCH:
      return { ...state, search: action.data };
    case actions.SET_ADVANCEDSEARCHDATA:
      return { ...state, advancedSearchData: action.data };
    case actions.SET_TAB_KEY:
      return { ...state, tabKey: action.data };
    case actions.RESET_DATA:
      return { ...initialState };
    default:
      return state;
  }
}
